import { Request, Response, NextFunction, RequestHandler } from "express";
import { getSession } from "../utils/sessionUtil";

export const isValidUser: RequestHandler = (
  req: Request,
  res: Response,
  next: NextFunction
) => {
  console.log("第一个中间件函数...");
  const session: any = getSession(req);
  if (session?.userInfo?.mark === "noallow") {
    res.setHeader("Content-Type", "text/html; charset=utf-8");
    res.write("您是被禁人士，被限制访问");
    res.end();
  } else {
    next(); // 进入到下一个中间件函数来执行,如果没有中间件,就直接执行请求方法
  }
};

export const secondMiddleware = (
  req: Request,
  res: Response,
  next: NextFunction
) => {
  console.log("第二个中间件函数....");
  next();
};
